package sourceFiles;

import Exceptions.InvalidAgeParam;
import Exceptions.InvalidChildID;
import Exceptions.InvalidHeightParam;
import Exceptions.TicketDoesntExist;

/**
 * A class containing all the relevant data for a child registered to the
 * system, including the tickets bought for the child and an interface on adding
 * and removing tickets. Inherits from PersonEntry class
 * 
 * @author LASO-Team
 * 
 */
public class ChildEntry extends PersonEntry {

	private final Integer age;
	private final Integer height;
	private Integer rideID = 0;
	private ETicket childsTicket;

	/*--------------------------------------------------------------------------*/

	/**
	 * A test for the legality of the entered parameters when building a new
	 * child entry
	 * 
	 * @param age
	 *            the age of the child.
	 * @param height
	 *            the height of the child.
	 * @throws InvalidAgeParam
	 *             if the age is invalid.
	 * @throws InvalidHeightParam
	 *             if height is invalid.
	 */
	private void checkParams(Integer age, Integer height)
			throws InvalidAgeParam, InvalidHeightParam {
		if (age < 1) {
			throw new InvalidAgeParam();
		} else if (height < 1) {
			throw new InvalidHeightParam();
		}
	}

	/*--------------------------------------------------------------------------*/
	/**
	 * A simple constructor for the ChildEntry
	 * 
	 * @param id
	 *            the ID of the child.
	 * @param age
	 *            the age id the child.
	 * @param height
	 *            the height of the child.
	 * @throws InvalidHeightParam
	 *             if the height given is less than 1.
	 * @throws InvalidAgeParam
	 *             if the age given is less than 1.
	 * @throws InvalidPersonID
	 *             if the id given is invalid.
	 */
	public ChildEntry(Integer id, Integer age, Integer height)
			throws InvalidChildID, InvalidAgeParam, InvalidHeightParam {
		super(id);
		if (id <= 0) {
			throw new InvalidChildID();
		}
		checkParams(age, height);
		this.age = age;
		this.height = height;
		this.childsTicket = new ETicket();
	}

	/**
	 * Getter for the child's E-Ticket
	 * 
	 * @return The childs record of it's current tickets, it's E-Ticket
	 */
	public ETicket getChildsTicket() {
		return childsTicket;
	}

	/**
	 * Setter for the current ride the child entered
	 * 
	 * @param rideID
	 *            the new ride the child is at
	 */
	public void setRideID(Integer rideID) {
		this.rideID = rideID;
	}

	/**
	 * Getter for the age of the child
	 * 
	 * @return the age of the child.
	 */
	public Integer getAge() {
		return age;
	}

	/**
	 * Getter for the height of the child
	 * 
	 * @return the height of the child.
	 */
	public Integer getHeight() {
		return height;
	}

	/**
	 * Getter for the current ride the child is on
	 * 
	 * @return the ride that the child is currently at. note that 0 means that
	 *         he has not yet visited a ride.
	 */
	public Integer getRideID() {
		return rideID;
	}

	/**
	 * Add a ticket to the child's E-Ticket, according to the ride's ID the
	 * guardian bought for the child
	 * 
	 * @param rideID
	 *            the ID of the ride that we are adding a ticket to is extreme.
	 *            Is ignored if isExtreme == false
	 * @param isExtreme
	 *            a boolean value that determines if the ride is extreme or not.
	 */
	public void addTicket(Integer rideID, Boolean isExtreme) {
		if (isExtreme) {
			this.childsTicket.addExtremeTicket(rideID);
		} else {
			this.childsTicket.addRegularTicket();
		}
	}

	/**
	 * Removing a ticket from the child's E-Ticket, according to the ride the
	 * child entered
	 * 
	 * @param rideID
	 *            the ID of the ride we are removing its ticket.
	 * @param isExtreme
	 *            a boolean value that determines if the ride is extreme or not.
	 * @throws TicketDoesntExist
	 *             if there is no ticket to remove.
	 */
	public void removeTicket(Integer rideID, Boolean isExtreme)
			throws TicketDoesntExist {
		if (!(this.childsTicket.ticketExists(rideID, isExtreme))) {
			throw new TicketDoesntExist();
		}
		if (isExtreme) {
			this.childsTicket.removeExtremeTicket(rideID);
		} else {
			this.childsTicket.removeRegularTicket();
		}
	}

	/**
	 * Tests if the child has a ticket to the RideID received
	 * @param rideID
	 *            the ID of the ride we wish to enter.
	 * @param isExtreme
	 *            a boolean value that determines if the ride is extreme or not.
	 * @return if there is a valid ticket to the ride.
	 */
	public Boolean existsTicket(Integer rideID, Boolean isExtreme) {
		return childsTicket.ticketExists(rideID, isExtreme);
	}
}
